/* 
 * File:   macros.h
 * Author: gustavo
 *
 * Created on July 15, 2011, 4:38 PM
 */

#ifndef MACROS_H
#define	MACROS_H

#include "msg.h"

#define _verify(expr) (expr)? (void)(0) : \
		msg_error( "_verify(%s)==0 present in function: %s.    [ %s:%d ]\n",\
		#expr, __func__, __FILE__, __LINE__ )




#ifndef ABS
#define ABS(a)		( (a)<0 ? -(a): (a) )
#endif

#ifndef SIGN
#define SIGN(a)		( (a)<0 ? -1 : 1 )
#endif

#ifndef MIN
#define MIN(a,b)	( (a)<(b) ? (a) : (b) )
#endif

#ifndef MAX
#define MAX(a,b)	( (a)>(b) ? (a) : (b) )
#endif

#define __CEIL(a)	( (a)>0	? (long)(a)+1 : (long)(a) )
#define CEIL(a)		( ( ( (a)-(long)(a) ) != 0 )	?	__CEIL(a)	:	( (long)(a) ) )

#define __FLOOR(a)	( ( (a)<0 )	?	( (long)(a)-1 )	:	( (long)(a) ) )
#define FLOOR(a)	( ( ( (a)-(long)(a) ) != 0 )	?	__FLOOR(a)	:	( (long)(a) ) )

#define FIX(a)		((a)>0)		?	FLOOR(a)		:	CEIL(a)
#define ROUND(a)	((a)>=0)	?	(long)((a)+0.5)	: (long)((a)-0.5)

#ifndef M_PI
#define M_PI		3.14159265358979323846	/* pi */
#endif

#define rad2deg(r) (r)*180/M_PI
#define deg2rad(r) (r)*M_PI/180



#ifndef NULL
#define NULL (0)
#endif

#ifdef	__cplusplus
extern "C" {
#endif



#ifdef	__cplusplus
}
#endif

#endif	/* MACROS_H */

